using System;
using FluentNHibernate.Mapping;
using Sample.Domain;

namespace Sample.Persistence.Mappings
{
    public sealed class PeerReviewMap : ClassMap<PeerReview>
    {
        public PeerReviewMap()
        {
            Id(x => x.Id).WithUnsavedValue(Guid.Empty)
                .GeneratedBy.GuidComb();
            Map(x => x.Description).Not.Nullable().WithLengthOf(25);
            
            References(x => x.ConductedFor)
                .Not.Nullable()
                .ColumnName("RevieweeId");

            HasMany(x => x.LinkToReviewers)
                .KeyColumnNames.Add("PeerReviewId") // Matches column name in join table
                .AsBag()
                .Inverse();
        }
    }
}